﻿using FluentValidation;
using FluentValidation.Validators;
using Portal.Core;
using Portal.Model;
using System.Text.RegularExpressions;

namespace Portal.Logic.Validators
{
	/// <summary>
	/// Class <see cref="ContactInfoValidator"/> define contact info validator
	/// </summary>
	public class ContactInfoValidator : BaseValidator<IContactInfo>, IContactInfoValidator
	{
		#region .ctor
		/// <summary>
		/// Initializes a new instance of the <see cref="UserValidator"/> class.
		/// </summary>
		public ContactInfoValidator()
		{
			RuleFor(x => x.Value)
				.NotEmpty()
				.Length(0, 50);

			RuleFor(x => x.Value)
                .EmailAddress()
                .When(x => x.Type == ContactInfoType.Email);
			RuleFor(x => x.Value)
                .Matches( RegularExpressions.POLISH_MOBILE_PHONE_NUMBER + "|" + RegularExpressions.POLISH_STATIONARY_PHONE_NUMBER)
                .When(x => x.Type == ContactInfoType.Phone);
		}
		#endregion
	}
}